﻿using CaterModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CaterDal
{
    public partial class HallInfoDal
    {
        public int Insert(HallInfo hi)
        {
            string sql = "insert into HallInfo(HTitle,HIsDelete) values(@HTitle,@HIsDelete)";
            SQLiteParameter[] ps = {
                new SQLiteParameter("@HTitle",hi.HTitle),
                 new SQLiteParameter("@HIsDelete",hi.HIsDelete)
            };
            return SqliteHelper.ExecuteNonQuery(sql, ps);
        }
        public int Delete(int id)
        {
            string sql = "update HallInfo set HIsDelete=1  where hid=@id";
            SQLiteParameter p = new SQLiteParameter("@id", id);
            return SqliteHelper.ExecuteNonQuery(sql, p);
        }
        public int Update(HallInfo hi)
        {
            string sql = "update  HallInfo set HTitle=@HTitle where hid=@id";
            SQLiteParameter[] ps ={
                new SQLiteParameter("@HTitle",hi.HTitle),
                new SQLiteParameter("@id",hi.HId)
            };
            return SqliteHelper.ExecuteNonQuery(sql, ps);
        }

        public List<HallInfo> GetList()
        {
            string sql = "select * from HallInfo where HisDelete=0";
            DataTable dt = SqliteHelper.GetDataTable(sql);
            List<HallInfo> list = new List<HallInfo>();
            foreach (DataRow dr in dt.Rows)
            {
                HallInfo hi = new HallInfo();
                hi.HId =Convert.ToInt32(dr["HId"].ToString());
                hi.HTitle = dr["HTitle"].ToString();
                list.Add(hi); 
            }

            return list;
        }
    }
}
